package com.fancy.mobileschool.ui.adapt;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.fancy.mobileschool.R;
import com.fancy.mobileschool.entity.Course;
import com.fancy.mobileschool.ui.CourseShareFileListActivity;

import java.util.List;

/**
 * Created by Jackie on 2017/11/14.
 */

public class CouseShareDirListAdapt extends RecyclerView.Adapter<CouseShareDirListAdapt.CourseDir> implements View.OnClickListener{

    private List<Course> courses;

    private Context context;

    public CouseShareDirListAdapt(List<Course> courses, Context context) {
        this.courses = courses;
        this.context = context;
    }

    @Override
    public CourseDir onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.course_dir_item, parent, false);
        return new CourseDir(view);
    }

    @Override
    public void onBindViewHolder(CourseDir holder, int position) {
        holder.course_dir_name.setText(courses.get(position).name);
        holder.view.setOnClickListener(this);
    }

    @Override
    public int getItemCount() {
        return courses.size();
    }

    @Override
    public void onClick(View view) {
        Intent i = new Intent(context, CourseShareFileListActivity.class);
        TextView textView = (TextView) view.findViewById(R.id.course_dir_name);
        i.putExtra("course_name", textView.getText());
        context.startActivity(i);
    }

    class CourseDir extends RecyclerView.ViewHolder {

        private TextView course_dir_name;

        private View view;

        public CourseDir(View itemView) {
            super(itemView);
            this.view = itemView;
            course_dir_name = (TextView) itemView.findViewById(R.id.course_dir_name);
        }

    }
}
